<?php
require_once 'Zend/Db/Table/Abstract.php';
class Model_DeliveryMapper extends Zend_Db_Table_Abstract {
	protected $_name = 'delivery';
	protected $_primary='DelID';
	protected $_referenceMap = array (
			'district' => array (
					'columns' => array ('DisID'),
					'refTableClass' => 'Model_DishMapper',
					'refColumns' => array ('DisID')
			),
			'location' => array (
					'columns' => array ('LocID'),
					'refTableClass' => 'Model_LocationMapper',
					'refColumns' => array ('LocID')
			)
	);
	public function getDelivery($id){
	
		$row=$this->fetchRow($this->select()->where('DelID=?',$id));
		$result= Array();
		if ($row)
		{
			$result['Id']=$row->DelID;
			$result['Time']=$row->Time;
			$result['Fee']=$row->Fee;
		}
		return $result;
	}
	
	public function getDeliveryOfLocation($locId){
		$result=Array();
		//$locM= new Model_LocationMapper();
		//$location=$locM->getLocation($locId);
		$i=0;
		$rowset = $this->fetchAll ( $this->select ()->where ( 'LocID=?', $locId ) )->toArray ();
		$rowCount = count ( $rowset );
		if ($rowCount > 0) {
			foreach ( $rowset as $row ) {
				$item = new Model_Delivery();
				$id=$row['DelID'];
				$time = $row ['Time'];
				$fee = $row ['Fee'];
				$disId = $row ['DisID'];
				$disMapper = new Model_DistrictMapper();
				$dis = $disMapper->getDistrict($disId);
				$item->setDistrict ( $dis )->setId($id)-> setTime ( $time )->setFee ( $fee );
				//$item->setLocation ( $loc );
				$result [$i] = $item;
				$i = $i + 1;
			}
		}
		return $result;
		
	}
	/*public function getLocationsByDelivery($disId){
		$rowset=$this->fetchAll($this->select()->where('DisID=?',$disId))->toArray();
		$rowCount = count($rowset);
		$result=Array();
		$i=0;
		if ($rowCount>0)
		{
			foreach ($rowset as $row) {
				$i=$i+1;
				$name = $row['Name'];
				$id = $row['DelID'];
	
				$disId=$row['DisID'];
				$disMapper=new Model_DistrictMapper();
				$district=$disMapper->getDistrict($disId);
	
				$address=$row['Address'];
				$phone=$row['Phone'];
				$description=$row['Description'];
				$image=$row['Image'];
				$del=new Model_Delivery();
				$del->setId($id)->setDistrict($district)->setName($name)->setAddress($address)->setPhone($phone)->setDescription($description);
				$result[$i]=$del;
			}
		}
		return $result;
	}*/
	public function getTotalLocationsByDelivery($disId){
		$rowset=$this->fetchAll($this->select()->where('DisID=?',$disId))->toArray();
		$rowCount = count($rowset);
		return $rowCount;
	}
}
?>